﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using LM.Negocio.Objetos;

namespace LM.Repositorios.Maps
{
    public class VeiculoMap : EntityTypeConfiguration<Veiculo>
    {
        public VeiculoMap()
        {
            this.HasKey(m => m.Id);
            this.Property(m => m.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).HasColumnName("Id");

            this.Property(c => c.Codigo).HasColumnName("Codigo").IsRequired();
            this.Property(c => c.Placa).HasColumnName("Placa").IsRequired();
            this.Property(c => c.Ano).HasColumnName("Ano").IsRequired();
            this.Property(c => c.Cor).HasColumnName("Cor").IsRequired();
            this.Property(c => c.TipoDeVeiculo).HasColumnName("TipoVeiculo").HasColumnType("int").IsRequired();

            this.HasRequired(c => c.Modelo)
                .WithMany(p => p.Veiculos)
                .HasForeignKey(s => s.ModeloId);

            this.HasRequired(m => m.Cliente)
                .WithMany(p => p.Veiculos)
                .HasForeignKey(s => s.ClienteId);

            this.ToTable("VEICULO");
        }
    }
}
